package com.quectel.util.kit;

import java.util.UUID;

/**
 * 链路追踪id生成器
 *
 * @author: caolu
 * @email: louis.cao@quectel.com
 * @date: 2022-12-01 13:44:00
 */
public class TraceIdKit {

    public static final String TRACE_ID_KEY = "traceId";

    private static final InheritableThreadLocal<String> THREAD_LOCAL = new InheritableThreadLocal<>();


    public static String getTraceId() {
        if (THREAD_LOCAL.get() == null) {
            THREAD_LOCAL.set(UUID.randomUUID().toString());
        }
        return THREAD_LOCAL.get();
    }

    public static void remove() {
        THREAD_LOCAL.remove();
    }
}
